var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollLeft:0,
    selected:0,
    scrollViewWidth:0,
    viewWidth:100,
    vipCategorys:[{id:1,name:'租车流程'},{id:2,name:'还车说明'},{id:3,name:'24H救援'},{id:4,name:'信用查询'},{id:5,name:'收费标准'},{id:6,name:'其他说明'}]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
 let that  = this;
    var deviceInfo = wx.getDeviceInfo();   
    let d = app.globalData;
      that.setData({
          width:d.windowWidth,
          height:d.windowHeight,
          statusBarHeight:d.statusBarHeight,
          navHeight:d.navHeight,
          marginTop:d.navTitleTop,
          bottom:d.bottom,
          domain:d.domain,
         imgUrl:d.imgUrl,
          platform:deviceInfo.platform
        })
  },
  chooseVipCategory(evt) {
    console.log(evt)
    const id = evt.currentTarget.dataset.id;
    let offsetLeft = evt.detail.x;
    console.log(offsetLeft);
    var  windowWidth =  this.data.width;
    var viewWidth = this.data.viewWidth;
    // 循环获取计算当前点击的标签项距离左侧的距离
    var width = 0;
    var scrollLeft = 0;
    for (let i = 0; i < id ; i++) {
        width = width + viewWidth +20;
    }
    // 当大于屏幕一半的宽度则滚动，否则就设置位置为0
    if (width > windowWidth / 2) {
        scrollLeft = width + viewWidth / 2 - windowWidth / 2
    } else {
        scrollLeft = 0
    }

    this.setData({
   //   intoView: `vip-category-${id}`,
      scrollLeft:scrollLeft,
      selected: parseInt(id, 10)
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
   

  },
  moveTo(index){
    wx.createSelectorQuery().select('.vip-category-item').boundingClientRect((rect)=>{
        console.log(rect)
    }).exec() 
  },
  goBack:function(){
    wx.navigateBack();
  },
  goIndex:function(){
    wx.reLaunch({
      url: '../index/index',
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})